// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Data.Common;
using Oracle.ManagedDataAccess.Client;

namespace SnapObjects.Data.Oracle
{
    /// <summary>
    ///     Represents the entry to the Oracle database.
    /// </summary>
    public class OracleDataContext : DataContext
    {
        /// <summary>
        ///     Initializes a new instance of the OracleDataContext class by passing the OracleDataContextOptions 
        ///     type object as a parameter.
        /// </summary>
        /// <param name="dataContextOptions">The options to be set for the DataContext object.</param>
        public OracleDataContext(IDataContextOptions dataContextOptions) :
            base(dataContextOptions)
        {
            this.AdoDbProviderFactory = new OracleAdoDbProviderFactory(this);
            this.AdoDbSqlProvider = new OracleAdoDbSqlProvider(this.ContextOptions);
            this.AdoDbSchemaProvider = new OracleAdoDbSchemaProvider(this);
        }

        /// <summary>
        ///     Initializes a new instance of the OracleDataContext class by passing the OracleConnection type object
        ///     as a parameter.
        /// </summary>
        /// <param name="dbConnection">The connection object which is an OracleConnection instance.</param>
        public OracleDataContext(OracleConnection dbConnection) :
            base(dbConnection, new OracleDataContextOptions(String.Empty))
        {
            this.AdoDbProviderFactory = new OracleAdoDbProviderFactory(this);
            this.AdoDbSqlProvider = new OracleAdoDbSqlProvider(this.ContextOptions);
            this.AdoDbSchemaProvider = new OracleAdoDbSchemaProvider(this);
        }

        internal override IAdoDbProviderFactory AdoDbProviderFactory { get; }

        internal override IAdoDbSchemaProvider AdoDbSchemaProvider { get; }

        internal override IAdoDbSqlProvider AdoDbSqlProvider { get; }

        internal override IAdoDbConnection CreateAdoDbConnection(string connectionString)
        {
            return new OracleAdoDbConnection(connectionString);
        }

        internal override IAdoDbConnection CreateAdoDbConnection(DbConnection dbConnection)
        {
            return new OracleAdoDbConnection((OracleConnection)dbConnection);
        }
    }
}
